package com.zhm.demo.util.sensitive;

import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
import com.github.houbb.sensitive.word.core.SensitiveWordHelper;
import com.github.houbb.sensitive.word.support.allow.WordAllows;
import com.github.houbb.sensitive.word.support.deny.WordDenys;
import com.github.houbb.sensitive.word.support.result.WordResultHandlers;

import java.util.List;

public class TestSensitive {
    public static void main(String[] args) {

        SensitiveWordBs wordBs = SensitiveWordBs.newInstance()
                .wordAllow(WordAllows.chains(WordAllows.system(), new MyDdWordAllow()))
                .wordDeny(WordDenys.chains(WordDenys.system(), new MyDdWordDeny()))
                .ignoreCase(true)
                .ignoreWidth(true)
                .ignoreNumStyle(true)
                .ignoreChineseStyle(true)
                .ignoreEnglishStyle(true)
                .ignoreRepeat(true)
                .enableNumCheck(true)
                .enableEmailCheck(true)
                .enableUrlCheck(true)
                .init();

        //是否有敏感词存在
        String text = "五星红旗迎风飘扬，画像屹立在天安门前。";
        boolean isFalse = wordBs.contains(text);
        System.out.println("是否有敏感词存在====>>>>" + isFalse);

        //返回所有敏感词
        List<String> wordList = wordBs.findAll(text);
        System.out.println("返回所有敏感词====>>>>" + wordList);

        //返回所有敏感词 等价于SensitiveWordHelper.findAll(text)
        wordList = wordBs.findAll(text, WordResultHandlers.word());
        System.out.println("返回所有敏感词====>>>>" + wordList);

        //返回字符串中第一个敏感词
        String first = wordBs.findFirst(text);
        System.out.println("返回字符串中第一个敏感词====>>>>" + first);

        //返回字符串中第一个敏感词 等价于SensitiveWordHelper.findFirst（text）
        first = wordBs.findFirst(text, WordResultHandlers.word());
        System.out.println("返回字符串中第一个敏感词====>>>>" + first);

        //默认的替换策略
        String result = wordBs.replace(text);
        System.out.println("默认的替换策略====>>>>" + result);

        //指定替换的内容 这里可以自定义替换内容
        result = wordBs.replace(text, '0');
        System.out.println("指定替换的内容====>>>>" + result);

        //自定义替换内容
        MySensitiveWordReplaceUtils mySensitiveWordReplaceUtils = new MySensitiveWordReplaceUtils();
        result = wordBs.replace(text, mySensitiveWordReplaceUtils);
        System.out.println("自定义替换内容====>>>>" + result);
    }
}
